

layui.define(['table', 'form','api',"utill"], function(exports){
  var $ = layui.$
  ,admin = layui.admin
  ,view = layui.view
  ,table = layui.table
  ,setter = layui.setter
  ,api = layui.api
  ,utill = layui.utill
  ,form = layui.form;

  //收款账户收款账户收款账户收款账户收款账户收款账户收款账户收款账户收款账户收款账户收款账户
  table.render({
    elem: '#LAY-app-content-list'
    ,url: api.host+ api.listPaymentAccount+`?userId=${layui.sessionData(setter.tableName).userId}&token=${layui.sessionData(setter.tableName).token}` //
    ,cols: [[
     
      {field: 'id',title: 'ID'}
      ,{field: 'bankName', title: '收款方式'}
      ,{field: 'address', title: '收款账号'}  
      ,{field: 'realname', title: '收款人'}
      ,{field: 'bankIndex', title: '支付宝用户ID'}
      ,{field: 'dailyMaxTotalMoney', title: '日收款上限'}
      ,{title: '操作',field:"splitBillFlag", minWidth: 150, align: 'left', fixed: 'right', toolbar: '#table-content-list'}
    ]]
    ,request: {
      pageName: 'current' //页码的参数名称，默认：page
      ,limitName: 'size' //每页数据量的参数名，默认：limit
    }
    ,page: true
    ,limit: 10
    ,limits: [10, 15, 20, 25, 30]
    ,text: {
      none: '暂无收款账户' 
    }
    ,parseData: function(res){ //res 即为原始返回的数据

      return {
        "code": res.code, //解析接口状态
        "msg": res.msg, //解析提示文本
        "count": res.data.total, //解析数据长度
        "data": res.data.records //解析数据列表
      }
    }
  });
  table.on('tool(LAY-app-content-list)', function(obj){
    
    var data = obj.data;
    if(obj.event === 'del'){

      layer.prompt({
        formType: 0
        ,title: '请输入谷歌验证码'
      }, function(value, index){
     
        admin.req({
          url: api.host+ api.deletePaymentAcount,
          data: {userId:layui.sessionData(setter.tableName).userId,
                  acountId: data.id,
                  validCode:value
          },
          type: "POST",
          done: function (res) {
            layui.table.reload('LAY-app-content-list'); //重载表格
            obj.del();
            layer.close(index);
          }
        });
      });
    } else if(obj.event === 'edit'){
      admin.popup({
        title: '编辑账户'
        ,area: ['420px', '380px']
        ,id: 'LAY-popup-content-edit'
        ,success: function(layero, index){       
          view(this.id).render('moneyManage/paymentAccountForm', data).done(function(){
            form.render(null, 'layuiadmin-app-form-list');
     
         
              
            form.val("layuiadmin-app-form-list", {
             "bank":data.acountType+"/"+data.bankName,
             "address":data.address,
             "realname":data.realname,
                "dailyMaxTotalMoney":data.dailyMaxTotalMoney
               })
              
            form.on('submit(layuiadmin-app-form-submit)', function(data){
              var field = data.field; //获取提交的字段
              field.userId = layui.sessionData(setter.tableName).userId
              field.id = obj.data.id
              field.bankName = field.bank.split('/')[1]
              admin.req({
                url:  api.host+ api.updatePaymentAcount,
                data: field,
                type: "POST",
                done: function (res) {
                  layui.table.reload('LAY-app-content-list'); //重载表格
              layer.close(index); //执行关闭 
                }
              });
             
            });
          });
        }
      });
    } else if(obj.event === 'set'){
      layer.prompt({
        formType: 0
        ,title: '请输入谷歌验证码'
      }, function(value, index){
          
        admin.req({
          url: api.host+ api.updateSplitBillFlag,
          data: {userId:layui.sessionData(setter.tableName).userId,
                   id: data.id,
                  validCode:value,
                  splitBillFlag:1
          },
          type: "POST",
          done: function (res) {
            layui.table.reload('LAY-app-content-list'); //重载表格
            layer.close(index);
          }
        });
      });
    }else if(obj.event === 'quexiao'){
      layer.prompt({
        formType: 0
        ,title: '请输入谷歌验证码'
      }, function(value, index){
          
        admin.req({
          url: api.host+ api.updateSplitBillFlag,
          data: {userId:layui.sessionData(setter.tableName).userId,
                   id: data.id,
                  validCode:value,
                  splitBillFlag:0
          },
          type: "POST",
          done: function (res) {
            layui.table.reload('LAY-app-content-list'); //重载表格
            layer.close(index);
          }
        });
      });
    }
  });
//提现记录现记录现记录现记录现记录现记录现记录现记录现记录现记录现记录现记录
  table.render({
    elem: '#LAY-app-tixian-list'
    ,url: api.host+ api.listCashApplyByUserId+`?userId=${layui.sessionData(setter.tableName).userId}&token=${layui.sessionData(setter.tableName).token}` 
    ,cols: [[
     
      {field: 'id', title: 'ID'}
      ,{field: 'money', title: '提现金额'}  
      ,{field: 'acountType', title: '收款方式'}
      ,{field: 'acountAddress', title: '收款账号'}  
     
      ,{field: 'acountRealname', title: '收款人'}
      ,{field: 'createTime', title: '提现时间', sort: true, 
      templet :function (row){
     return utill.timestampToTime(row.createTime);
    }     }
      ,{field: 'state', title: '状态',  minWidth: 80, align: 'center',templet: '#buttonTpl'}
      ,{field: 'remarks', title: '拒绝理由',
      templet :function (row){
        if (row.remarks) {
          return row.remarks
        }else{
          return "-"
        }
   
    }     }
    ]]
    ,request: {
      pageName: 'current' //页码的参数名称，默认：page
      ,limitName: 'size' //每页数据量的参数名，默认：limit
    }
    ,page: true
    ,limit: 10
    ,limits: [10, 15, 20, 25, 30]
    ,text: {
      none: '该商户暂无提现记录' //默认：无数据。注：该属性为 layui 2.2.5 开始新增
    }
    ,parseData: function(res){ //res 即为原始返回的数据

      
      return {
        "code": res.code, //解析接口状态
        "msg": res.msg, //解析提示文本
        "count": res.data.total, //解析数据长度
        "data": res.data.records //解析数据列表
      }
    }
  });


   //余额记录余额记录余额记录余额记录余额记录余额记录余额记录余额记录余额记录余额记录
   table.render({
    elem: '#LAY-app-forum-list'
    ,url:  api.host+ api.balanceRecord+`?userId=${layui.sessionData(setter.tableName).userId}&token=${layui.sessionData(setter.tableName).token}` //
    ,cols: [[
     
      {field: 'id',  title: 'ID'}
      ,{field: 'money', title: '金额'}
      ,{field: 'createTime', title: '时间', sort: true, 
        templet :function (row){
       return utill.timestampToTime(row.createTime);
      }     }
      ,
      {
        field: 'balance',
        title: '结余',
  
      }
      ,{field: 'type', title: '状态', templet: '#buttonTpl', minWidth: 80, align: 'center'}
      ,{field: 'remarks', title: '原因', minWidth: 80, align: 'center'}

    ]]
    ,request: {
      pageName: 'current' //页码的参数名称，默认：page
      ,limitName: 'size' //每页数据量的参数名，默认：limit
    }
    ,page: true
    ,limit: 10
    ,limits: [10, 15, 20, 25, 30]
    ,text: {
      none: '暂无余额记录' 
    }
    ,parseData: function(res){ //res 即为原始返回的数

      
      return {
        "code": res.code, //解析接口状态
        "msg": res.msg, //解析提示文本
        "count": res.data.total, //解析数据长度
        "data": res.data.records, //解析数据列表
      
      }
    }
  });

  exports('contlist', {})
});